using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using OgilvyOne.IDAL;
using OgilvyOne.Utility;
using OgilvyOne.Model;

namespace OgilvyOne.SqlServerDAL
{
    public class HistoryModule : CommonModule
    {
        // Methods
        private string GetDetailContent(int menuId, int contentId, int pageIndex)
        {
            GroupModule module = new GroupModule();
            return module.GetIndexContent(menuId, contentId, pageIndex);
        }

        private string GetHistoryList(int menuId, int contentId, int pageIndex, bool isRootId)
        {
            StringBuilder builder = new StringBuilder();
            string str = string.Empty;
            string str2 = string.Empty;
            string str3 = string.Empty;
            MenuDescInfo cacheMenuDesc = new MenuDesc().GetCacheMenuDesc(menuId);
            if (cacheMenuDesc != null)
            {
                str = cacheMenuDesc.Menu_desc;
                str2 = cacheMenuDesc.Menu_title;
                str3 = cacheMenuDesc.Menu_content;
            }
            builder.AppendFormat("<div id='contentCenter'>\r\n\t\t\t\t\r\n\t\t\t\t<div id='contentTitle'>\r\n\t\t\t\t\t{0}\r\n\t\t\t\t</div><!--contentTitle--><ul id='verticalMenu'>", str2);
            int cnOrEnMenuId = base.sm.GetCnOrEnMenuId("history_index_id", menuId);
            IList subMenuList = base.sm.GetSubMenuList(cnOrEnMenuId);
            int num3 = 0;
            if ((subMenuList != null) && (subMenuList.Count > 0))
            {
                int num4;
                for (num4 = 0; num4 < subMenuList.Count; num4++)
                {
                    SysMenuInfo info2 = (SysMenuInfo)subMenuList[num4];
                    string ret = "/cds/?menu_uid=" + info2.Node_ID.ToString();
                    SColumnInfo sci = new SColumnInfo();
                    MColumnInfo mci = sci.GetRowByPrimaryKey(info2.Node_ID,0);
                    if (mci != null)
                    {
                        ret = "/" + mci.FolderName + mci.FileName;
                    }
                    if ((isRootId && (num4 == 0)) || (menuId == info2.Node_ID))
                    {
                        num3 = info2.Node_ID;
                        builder.AppendFormat("<li class='current'><a href='{0}'>{1}</a></li>", ret, info2.Node_Name);
                    }
                    else
                    {
                        builder.AppendFormat("<li><a href='{0}'>{1}</a></li>", ret, info2.Node_Name);
                    }
                }
                ContentClass class2 = new ContentClass();
                IList list2 = new ArrayList();
                list2 = class2.getContentList1(num3);
                if (list2.Count > 0)
                {
                    for (num4 = 0; num4 < list2.Count; num4++)
                    {
                        ConInfo info3 = (ConInfo)list2[num4];
                        if ((num4 % 2) == 0)
                        {
                            builder.AppendFormat("</ul><ul class='historyList'>\r\n\t\t\t\t\t<li class='time'>{0}</li>\r\n\t\t\t\t\t<li class='content'>{1}</li>\r\n\t\t\t\t</ul>", info3.Con_Title, info3.Con_Desc);
                        }
                        else
                        {
                            builder.AppendFormat("<ul class='historyList even'>\r\n\t\t\t\t\t<li class='time'>{0}</li>\r\n\t\t\t\t\t<li class='content'>{1}</li>\r\n\t\t\t\t</ul>", info3.Con_Title, info3.Con_Desc);
                        }
                    }
                }
            }
            builder.AppendFormat("</div><!--contentCenter-->", new object[0]);
            return builder.ToString();
        }

        private string GetHistoryListEmpty(int menuId, int contentId, int pageIndex)
        {
            return string.Empty;
        }

        private string GetReplacedContent(int menuId, int contentId, int pageIndex)
        {
            if (contentId > 0)
            {
                return this.GetDetailContent(menuId, contentId, pageIndex);
            }
            int cnOrEnSubRootId = base.sm.GetCnOrEnSubRootId(menuId);
            if (menuId == cnOrEnSubRootId)
            {
                return this.GetHistoryList(menuId, contentId, pageIndex, true);
            }
            return this.GetHistoryList(menuId, contentId, pageIndex, false);
        }

        protected override string ReplaceContent(string templateContent, string replacedContent, int menuId, int contentId, int pageIndex, string searchType, string searchKey)
        {
            string str = replacedContent;
            if (templateContent.IndexOf("#####content#####") > 0)
            {
                str = StringUtil.ReplaceStr(str, "#####content#####", this.GetReplacedContent(menuId, contentId, pageIndex));
            }
            return str;
        }
    }
}